home *** CD-ROM | disk | FTP | other *** search
- /*
- GlobalPatch.c
-
- Sub-class of TrapPatch that uses the SetTrapAddress available at INIT time
- to patch in every context of the system.
-
- Part of PatchWorks, the Extension Development Framework.
-
- by Mouse Herrell & Patrick Beard.
-
- Permission is granted to use this source code for any purpose, as long
- as the copyright notice is maintained.
-
- © 1992 Berkeley Systems, Inc.
- */
-
- #include "GlobalPatch.h"
-
- #define GetTrapAddress_Trap 0xA146
- #define NGetTrapAddress_Tool 0xA646
- #define NGetTrapAddress_OS 0xA246
-
- #define SetTrapAddress_Trap 0xA047
- #define NSetTrapAddress_Tool 0xA647
- #define NSetTrapAddress_OS 0xA247
-
- PatchProcPtr GlobalPatch::theirGetTrapAddress;
- PatchProcPtr GlobalPatch::theirSetTrapAddress;
-
- void GlobalPatch::SaveTrapAddresses()
- {
- theirGetTrapAddress = (PatchProcPtr)NGetTrapAddress(GetTrapAddress_Trap, GetTrapType(GetTrapAddress_Trap));
- theirSetTrapAddress = (PatchProcPtr)NGetTrapAddress(SetTrapAddress_Trap, GetTrapType(SetTrapAddress_Trap));
- }
-
- PatchProcPtr GlobalPatch::Get()
- {
- ProcPtr trapAddr;
- Boolean toolTrap = GetTrapType(itsTrap);
-
- #ifdef THINK_C
- asm {
- move.w this->itsTrap, d0
- move.b toolTrap, d1
- beq.s @0
- move.w #NGetTrapAddress_Tool, d1
- bra.s @1
- @0 move.w #NGetTrapAddress_OS, d1
- @1 move.l theirGetTrapAddress, a0
- jsr (a0)
- move.l a0, trapAddr
- }
- #endif
-
- return trapAddr;
- }
-
- void GlobalPatch::Set(PatchProcPtr proc)
- {
- Boolean toolTrap = GetTrapType(itsTrap);
-
- #ifdef THINK_C
- asm {
- move.w this->itsTrap, d0
- move.l proc, a0
- move.b toolTrap, d1
- beq.s @0
- move.w #NSetTrapAddress_Tool, d1
- bra.s @1
- @0 move.w #NSetTrapAddress_OS, d1
- @1 move.l theirSetTrapAddress, a1
- jsr (a1)
- }
- #endif
-
- }
-